package com.codeoss.module.stock.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.module.ir.service.IIrReportQueryService;
import com.codeoss.module.stock.service.IStockInStatisticsReportService;

@Service
public class StockInStatisticsReportService implements IStockInStatisticsReportService {
	@Autowired
	private IIrReportQueryService irReportQueryService;
	public List<Map<String,Object>> loadData(String dsName,String datasetName,Map<String,Object> parameters){
		List<Map<String,Object>> list=irReportQueryService.search("stock_in_statistics_report", parameters);
		for(int i=0;i<list.size();i++) {
			Map<String,Object> dataMap=list.get(i);
			BigDecimal otherQtySum=(BigDecimal)dataMap.get("other_qty_sum");
			if(otherQtySum==null) {
				otherQtySum=new BigDecimal(0);
				dataMap.put("other_qty_sum", otherQtySum);
			}
			BigDecimal purchaseQtySum=(BigDecimal)dataMap.get("purchase_qty_sum");
			if(purchaseQtySum==null) {
				purchaseQtySum=new BigDecimal(0);
				dataMap.put("purchase_qty_sum", purchaseQtySum);
			}
			BigDecimal returnQtySum=(BigDecimal)dataMap.get("return_qty_sum");
			if(returnQtySum==null) {
				returnQtySum=new BigDecimal(0);
				dataMap.put("return_qty_sum", returnQtySum);
			}
			dataMap.put("qty_sum", otherQtySum.add(purchaseQtySum).add(returnQtySum));
		}
		return list;
	}
}
